package com.example.demo;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/request")
@RestController
public class RequestController {
    //建立客户端和服务器之间的连接，括号里表示的是url
    //@RequestMapping即可修饰类路径也可以修饰方法路径，类路径可有可无，方法路径必须有
    @RequestMapping("/hello")
    public String say(){
        return "hello,spring mvc";
    }

    @RequestMapping("/r1")
    public String r1(String name,Integer age){
        return "接收姓名：name="+name+"接收年龄：age="+age;
    }

    @RequestMapping("/r2")
    public String r2(Student student){
        return "接收参数:"+student;
    }

    //一旦使用了@RequestParam接口，这个name就成为了一个必传参数
    @RequestMapping("/r3")
    public String r3(@RequestParam("name") String username){
        return "接收姓名:"+username;
    }

    //如果不想报错，就将required设为false
    @RequestMapping("/r4")
    public String r4(@RequestParam(value = "name",required = false) String username){
        return "接收姓名:"+username;
    }

//    @RequestMapping("/r2")
//    public String r2(int age){
//        return "接收年龄：age="+age;
//    }
}
